// $ANTLR 3.4 C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g 2012-05-09 19:00:37

	package data.analysis.grammar;
	
	import java.io.ByteArrayInputStream;
	import java.io.IOException;
	import java.util.Map;
	import data.analysis.grammar.symbol.Scope;
	import script.grammar.FilterTranslator;
	import stream.ErrorStream;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;
import java.util.HashMap;
@SuppressWarnings({"all", "warnings", "unchecked"})
public class LocStatGen extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "COND", "COND_DEFAULT", "COND_OP", "COUNT", "DEFINE", "ESC_SEQ", "EXACTLY_ONE", "FRACTION", "HEX_DIGIT", "ID", "MEAN", "MEDIAN", "NOT", "OCTAL_ESC", "ONE_OR_MORE", "SCOPE_OP", "SCRIPT", "STRING", "SUBJECT", "UNICODE_ESC", "WS", "'('", "')'", "','", "';'", "'{'", "'}'"
    };

    public static final int EOF=-1;
    public static final int T__25=25;
    public static final int T__26=26;
    public static final int T__27=27;
    public static final int T__28=28;
    public static final int T__29=29;
    public static final int T__30=30;
    public static final int COND=4;
    public static final int COND_DEFAULT=5;
    public static final int COND_OP=6;
    public static final int COUNT=7;
    public static final int DEFINE=8;
    public static final int ESC_SEQ=9;
    public static final int EXACTLY_ONE=10;
    public static final int FRACTION=11;
    public static final int HEX_DIGIT=12;
    public static final int ID=13;
    public static final int MEAN=14;
    public static final int MEDIAN=15;
    public static final int NOT=16;
    public static final int OCTAL_ESC=17;
    public static final int ONE_OR_MORE=18;
    public static final int SCOPE_OP=19;
    public static final int SCRIPT=20;
    public static final int STRING=21;
    public static final int SUBJECT=22;
    public static final int UNICODE_ESC=23;
    public static final int WS=24;

    // delegates
    public TreeParser[] getDelegates() {
        return new TreeParser[] {};
    }

    // delegators


    public LocStatGen(TreeNodeStream input) {
        this(input, new RecognizerSharedState());
    }
    public LocStatGen(TreeNodeStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected StringTemplateGroup templateLib =
  new StringTemplateGroup("LocStatGenTemplates", AngleBracketTemplateLexer.class);

public void setTemplateLib(StringTemplateGroup templateLib) {
  this.templateLib = templateLib;
}
public StringTemplateGroup getTemplateLib() {
  return templateLib;
}
/** allows convenient multi-value initialization:
 *  "new STAttrMap().put(...).put(...)"
 */
public static class STAttrMap extends HashMap {
  public STAttrMap put(String attrName, Object value) {
    super.put(attrName, value);
    return this;
  }
  public STAttrMap put(String attrName, int value) {
    super.put(attrName, new Integer(value));
    return this;
  }
}
    public String[] getTokenNames() { return LocStatGen.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g"; }


    	protected OutputDictionary dictionary;
    	protected int nDefn = 0;
    	
    	protected FilterTranslator trans;
    	protected Map<Scope,Class<?>> filterTypeMap;
    	
    	protected ErrorStream err;
    	
    	public LocStatGen(TreeNodeStream in, OutputDictionary dictionary, FilterTranslator trans,
    			Map<Scope,Class<?>> filterTypeMap, ErrorStream err) {
    		this(in);
    		this.dictionary = dictionary;
    		this.trans = trans;
    		this.filterTypeMap = filterTypeMap;
    		this.err = err;
    	}
    	
    	protected String[] getFilterBody(LocStatAST string) {
    		try {
    			String raw = string.getText();
       			String targetCode = trans.buildTargetCode(new ByteArrayInputStream(raw.substring(1, raw.length() - 1).getBytes()),
       					filterTypeMap.get(string.scope), "", FilterTranslator.CODE_MODE_BODY);
       			if (targetCode == null) {
       				throw new IOException();
       			}
       			
       			return new String[] {targetCode, filterTypeMap.get(string.scope).getName()};
       		} catch (IOException e) {
       			this.err.write("Error: A problem occured while parsing custom filter code.");
       			throw new RuntimeException();
       		}
    	}


    public static class start_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "start"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:55:1: start : (s+= defn )+ -> defns(stats=$s);
    public final LocStatGen.start_return start() throws RecognitionException {
        LocStatGen.start_return retval = new LocStatGen.start_return();
        retval.start = input.LT(1);


        List list_s=null;
        RuleReturnScope s = null;
        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:56:2: ( (s+= defn )+ -> defns(stats=$s))
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:56:4: (s+= defn )+
            {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:56:4: (s+= defn )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==DEFINE) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:56:5: s+= defn
            	    {
            	    pushFollow(FOLLOW_defn_in_start51);
            	    s=defn();

            	    state._fsp--;

            	    if (list_s==null) list_s=new ArrayList();
            	    list_s.add(s.getTemplate());


            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            // TEMPLATE REWRITE
            // 56:15: -> defns(stats=$s)
            {
                retval.st = templateLib.getInstanceOf("defns",new STAttrMap().put("stats", list_s));
            }



            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "start"


    public static class defn_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "defn"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:59:1: defn : ^( DEFINE STRING func ) -> stat(func=$func.stname=$STRING.textid=\"\"+nDefn++);
    public final LocStatGen.defn_return defn() throws RecognitionException {
        LocStatGen.defn_return retval = new LocStatGen.defn_return();
        retval.start = input.LT(1);


        LocStatAST STRING2=null;
        LocStatGen.func_return func1 =null;


        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:59:5: ( ^( DEFINE STRING func ) -> stat(func=$func.stname=$STRING.textid=\"\"+nDefn++))
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:59:7: ^( DEFINE STRING func )
            {
            match(input,DEFINE,FOLLOW_DEFINE_in_defn73); 

            match(input, Token.DOWN, null); 
            STRING2=(LocStatAST)match(input,STRING,FOLLOW_STRING_in_defn75); 

            pushFollow(FOLLOW_func_in_defn77);
            func1=func();

            state._fsp--;


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 59:29: -> stat(func=$func.stname=$STRING.textid=\"\"+nDefn++)
            {
                retval.st = templateLib.getInstanceOf("stat",new STAttrMap().put("func", (func1!=null?func1.st:null)).put("name", (STRING2!=null?STRING2.getText():null)).put("id", ""+nDefn++));
            }



            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "defn"


    public static class func_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "func"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:62:1: func : ( ^( COUNT count ) -> countFunc(body=$count.st)| ^( FRACTION a= count b= count ) -> fractionFunc(num=$a.stdenom=$b.st)| ^( MEAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) ) -> meanFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st)| ^( MEDIAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) ) -> medFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st));
    public final LocStatGen.func_return func() throws RecognitionException {
        LocStatGen.func_return retval = new LocStatGen.func_return();
        retval.start = input.LT(1);


        LocStatAST ID4=null;
        LocStatAST ID6=null;
        List list_s=null;
        LocStatGen.count_return a =null;

        LocStatGen.count_return b =null;

        LocStatGen.count_return count3 =null;

        LocStatGen.count_return count5 =null;

        LocStatGen.count_return count7 =null;

        RuleReturnScope s = null;
        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:62:5: ( ^( COUNT count ) -> countFunc(body=$count.st)| ^( FRACTION a= count b= count ) -> fractionFunc(num=$a.stdenom=$b.st)| ^( MEAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) ) -> meanFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st)| ^( MEDIAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) ) -> medFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st))
            int alt4=4;
            switch ( input.LA(1) ) {
            case COUNT:
                {
                alt4=1;
                }
                break;
            case FRACTION:
                {
                alt4=2;
                }
                break;
            case MEAN:
                {
                alt4=3;
                }
                break;
            case MEDIAN:
                {
                alt4=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:62:7: ^( COUNT count )
                    {
                    match(input,COUNT,FOLLOW_COUNT_in_func108); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_count_in_func110);
                    count3=count();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 62:22: -> countFunc(body=$count.st)
                    {
                        retval.st = templateLib.getInstanceOf("countFunc",new STAttrMap().put("body", (count3!=null?count3.st:null)));
                    }



                    }
                    break;
                case 2 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:63:4: ^( FRACTION a= count b= count )
                    {
                    match(input,FRACTION,FOLLOW_FRACTION_in_func126); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_count_in_func130);
                    a=count();

                    state._fsp--;


                    pushFollow(FOLLOW_count_in_func134);
                    b=count();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 63:32: -> fractionFunc(num=$a.stdenom=$b.st)
                    {
                        retval.st = templateLib.getInstanceOf("fractionFunc",new STAttrMap().put("num", (a!=null?a.st:null)).put("denom", (b!=null?b.st:null)));
                    }



                    }
                    break;
                case 3 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:64:4: ^( MEAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) )
                    {
                    match(input,MEAN,FOLLOW_MEAN_in_func155); 

                    match(input, Token.DOWN, null); 
                    match(input,SUBJECT,FOLLOW_SUBJECT_in_func158); 

                    match(input, Token.DOWN, null); 
                    ID4=(LocStatAST)match(input,ID,FOLLOW_ID_in_func160); 

                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:64:24: (s+= condBase )*
                    loop2:
                    do {
                        int alt2=2;
                        int LA2_0 = input.LA(1);

                        if ( (LA2_0==COND) ) {
                            alt2=1;
                        }


                        switch (alt2) {
                    	case 1 :
                    	    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:64:25: s+= condBase
                    	    {
                    	    pushFollow(FOLLOW_condBase_in_func165);
                    	    s=condBase();

                    	    state._fsp--;

                    	    if (list_s==null) list_s=new ArrayList();
                    	    list_s.add(s.getTemplate());


                    	    }
                    	    break;

                    	default :
                    	    break loop2;
                        }
                    } while (true);


                    match(input, Token.UP, null); 


                    match(input,SCOPE_OP,FOLLOW_SCOPE_OP_in_func171); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_count_in_func173);
                    count5=count();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 65:4: -> meanFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st)
                    {
                        retval.st = templateLib.getInstanceOf("meanFunc",new STAttrMap().put("type", dictionary.get(ID4).type).put("getter", dictionary.get(ID4).getter).put("conds", list_s).put("attr", (count5!=null?count5.st:null)));
                    }



                    }
                    break;
                case 4 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:66:4: ^( MEDIAN ^( SUBJECT ID (s+= condBase )* ) ^( SCOPE_OP count ) )
                    {
                    match(input,MEDIAN,FOLLOW_MEDIAN_in_func209); 

                    match(input, Token.DOWN, null); 
                    match(input,SUBJECT,FOLLOW_SUBJECT_in_func212); 

                    match(input, Token.DOWN, null); 
                    ID6=(LocStatAST)match(input,ID,FOLLOW_ID_in_func214); 

                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:66:26: (s+= condBase )*
                    loop3:
                    do {
                        int alt3=2;
                        int LA3_0 = input.LA(1);

                        if ( (LA3_0==COND) ) {
                            alt3=1;
                        }


                        switch (alt3) {
                    	case 1 :
                    	    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:66:27: s+= condBase
                    	    {
                    	    pushFollow(FOLLOW_condBase_in_func219);
                    	    s=condBase();

                    	    state._fsp--;

                    	    if (list_s==null) list_s=new ArrayList();
                    	    list_s.add(s.getTemplate());


                    	    }
                    	    break;

                    	default :
                    	    break loop3;
                        }
                    } while (true);


                    match(input, Token.UP, null); 


                    match(input,SCOPE_OP,FOLLOW_SCOPE_OP_in_func225); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_count_in_func227);
                    count7=count();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 66:61: -> medFunc(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$sattr=$count.st)
                    {
                        retval.st = templateLib.getInstanceOf("medFunc",new STAttrMap().put("type", dictionary.get(ID6).type).put("getter", dictionary.get(ID6).getter).put("conds", list_s).put("attr", (count7!=null?count7.st:null)));
                    }



                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "func"


    public static class count_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "count"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:69:1: count : ^( SUBJECT ID (s+= condBase )* ) -> count(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$s);
    public final LocStatGen.count_return count() throws RecognitionException {
        LocStatGen.count_return retval = new LocStatGen.count_return();
        retval.start = input.LT(1);


        LocStatAST ID8=null;
        List list_s=null;
        RuleReturnScope s = null;
        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:70:2: ( ^( SUBJECT ID (s+= condBase )* ) -> count(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$s))
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:70:4: ^( SUBJECT ID (s+= condBase )* )
            {
            match(input,SUBJECT,FOLLOW_SUBJECT_in_count266); 

            match(input, Token.DOWN, null); 
            ID8=(LocStatAST)match(input,ID,FOLLOW_ID_in_count268); 

            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:70:17: (s+= condBase )*
            loop5:
            do {
                int alt5=2;
                int LA5_0 = input.LA(1);

                if ( (LA5_0==COND) ) {
                    alt5=1;
                }


                switch (alt5) {
            	case 1 :
            	    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:70:18: s+= condBase
            	    {
            	    pushFollow(FOLLOW_condBase_in_count273);
            	    s=condBase();

            	    state._fsp--;

            	    if (list_s==null) list_s=new ArrayList();
            	    list_s.add(s.getTemplate());


            	    }
            	    break;

            	default :
            	    break loop5;
                }
            } while (true);


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 70:33: -> count(type=dictionary.get($ID).typegetter=dictionary.get($ID).getterconds=$s)
            {
                retval.st = templateLib.getInstanceOf("count",new STAttrMap().put("type", dictionary.get(ID8).type).put("getter", dictionary.get(ID8).getter).put("conds", list_s));
            }



            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "count"


    public static class condBase_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "condBase"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:73:1: condBase : ( ^( COND ( COND_DEFAULT | NOT ) ^( SUBJECT ID ) ) -> condBase(body=%cond(not={not}, bool={dictionary.get($ID).getter}))| ^( COND numOp ^( SUBJECT ID (s+= condBase )* ) ) -> condBase(body=%numCond(type={dictionary.get($ID).type}, getter={dictionary.get($ID).getter}, conds={$s}, numOp={$numOp.st}))| ^( COND NOT a= condBase ) -> condBase(body=%cond(not={true}, bool={$a.st}))| ^( COND SCRIPT STRING ) -> condBase(body=%script(typeName={filterArgs[1]}, body={filterArgs[0]})));
    public final LocStatGen.condBase_return condBase() throws RecognitionException {
        LocStatGen.condBase_return retval = new LocStatGen.condBase_return();
        retval.start = input.LT(1);


        LocStatAST ID9=null;
        LocStatAST ID10=null;
        LocStatAST STRING12=null;
        List list_s=null;
        LocStatGen.condBase_return a =null;

        LocStatGen.numOp_return numOp11 =null;

        RuleReturnScope s = null;
        boolean not = false;
        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:75:2: ( ^( COND ( COND_DEFAULT | NOT ) ^( SUBJECT ID ) ) -> condBase(body=%cond(not={not}, bool={dictionary.get($ID).getter}))| ^( COND numOp ^( SUBJECT ID (s+= condBase )* ) ) -> condBase(body=%numCond(type={dictionary.get($ID).type}, getter={dictionary.get($ID).getter}, conds={$s}, numOp={$numOp.st}))| ^( COND NOT a= condBase ) -> condBase(body=%cond(not={true}, bool={$a.st}))| ^( COND SCRIPT STRING ) -> condBase(body=%script(typeName={filterArgs[1]}, body={filterArgs[0]})))
            int alt8=4;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==COND) ) {
                int LA8_1 = input.LA(2);

                if ( (LA8_1==DOWN) ) {
                    switch ( input.LA(3) ) {
                    case NOT:
                        {
                        int LA8_3 = input.LA(4);

                        if ( (LA8_3==COND) ) {
                            alt8=3;
                        }
                        else if ( (LA8_3==SUBJECT) ) {
                            alt8=1;
                        }
                        else {
                            NoViableAltException nvae =
                                new NoViableAltException("", 8, 3, input);

                            throw nvae;

                        }
                        }
                        break;
                    case SCRIPT:
                        {
                        alt8=4;
                        }
                        break;
                    case COND_DEFAULT:
                        {
                        alt8=1;
                        }
                        break;
                    case EXACTLY_ONE:
                    case ONE_OR_MORE:
                        {
                        alt8=2;
                        }
                        break;
                    default:
                        NoViableAltException nvae =
                            new NoViableAltException("", 8, 2, input);

                        throw nvae;

                    }

                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 8, 1, input);

                    throw nvae;

                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 0, input);

                throw nvae;

            }
            switch (alt8) {
                case 1 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:75:4: ^( COND ( COND_DEFAULT | NOT ) ^( SUBJECT ID ) )
                    {
                    match(input,COND,FOLLOW_COND_in_condBase312); 

                    match(input, Token.DOWN, null); 
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:75:11: ( COND_DEFAULT | NOT )
                    int alt6=2;
                    int LA6_0 = input.LA(1);

                    if ( (LA6_0==COND_DEFAULT) ) {
                        alt6=1;
                    }
                    else if ( (LA6_0==NOT) ) {
                        alt6=2;
                    }
                    else {
                        NoViableAltException nvae =
                            new NoViableAltException("", 6, 0, input);

                        throw nvae;

                    }
                    switch (alt6) {
                        case 1 :
                            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:75:12: COND_DEFAULT
                            {
                            match(input,COND_DEFAULT,FOLLOW_COND_DEFAULT_in_condBase315); 

                            not = false;

                            }
                            break;
                        case 2 :
                            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:75:40: NOT
                            {
                            match(input,NOT,FOLLOW_NOT_in_condBase319); 

                            not = true;

                            }
                            break;

                    }


                    match(input,SUBJECT,FOLLOW_SUBJECT_in_condBase325); 

                    match(input, Token.DOWN, null); 
                    ID9=(LocStatAST)match(input,ID,FOLLOW_ID_in_condBase327); 

                    match(input, Token.UP, null); 


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 75:74: -> condBase(body=%cond(not={not}, bool={dictionary.get($ID).getter}))
                    {
                        retval.st = templateLib.getInstanceOf("condBase",new STAttrMap().put("body", templateLib.getInstanceOf("cond",new STAttrMap().put("not", not).put("bool", dictionary.get(ID9).getter))));
                    }



                    }
                    break;
                case 2 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:76:4: ^( COND numOp ^( SUBJECT ID (s+= condBase )* ) )
                    {
                    match(input,COND,FOLLOW_COND_in_condBase344); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_numOp_in_condBase346);
                    numOp11=numOp();

                    state._fsp--;


                    match(input,SUBJECT,FOLLOW_SUBJECT_in_condBase349); 

                    match(input, Token.DOWN, null); 
                    ID10=(LocStatAST)match(input,ID,FOLLOW_ID_in_condBase351); 

                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:76:30: (s+= condBase )*
                    loop7:
                    do {
                        int alt7=2;
                        int LA7_0 = input.LA(1);

                        if ( (LA7_0==COND) ) {
                            alt7=1;
                        }


                        switch (alt7) {
                    	case 1 :
                    	    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:76:31: s+= condBase
                    	    {
                    	    pushFollow(FOLLOW_condBase_in_condBase356);
                    	    s=condBase();

                    	    state._fsp--;

                    	    if (list_s==null) list_s=new ArrayList();
                    	    list_s.add(s.getTemplate());


                    	    }
                    	    break;

                    	default :
                    	    break loop7;
                        }
                    } while (true);


                    match(input, Token.UP, null); 


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 76:47: -> condBase(body=%numCond(type={dictionary.get($ID).type}, getter={dictionary.get($ID).getter}, conds={$s}, numOp={$numOp.st}))
                    {
                        retval.st = templateLib.getInstanceOf("condBase",new STAttrMap().put("body", templateLib.getInstanceOf("numCond",new STAttrMap().put("type", dictionary.get(ID10).type).put("getter", dictionary.get(ID10).getter).put("conds", list_s).put("numOp", (numOp11!=null?numOp11.st:null)))));
                    }



                    }
                    break;
                case 3 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:77:4: ^( COND NOT a= condBase )
                    {
                    match(input,COND,FOLLOW_COND_in_condBase375); 

                    match(input, Token.DOWN, null); 
                    match(input,NOT,FOLLOW_NOT_in_condBase377); 

                    pushFollow(FOLLOW_condBase_in_condBase381);
                    a=condBase();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 77:27: -> condBase(body=%cond(not={true}, bool={$a.st}))
                    {
                        retval.st = templateLib.getInstanceOf("condBase",new STAttrMap().put("body", templateLib.getInstanceOf("cond",new STAttrMap().put("not", true).put("bool", (a!=null?a.st:null)))));
                    }



                    }
                    break;
                case 4 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:78:4: ^( COND SCRIPT STRING )
                    {
                    match(input,COND,FOLLOW_COND_in_condBase397); 

                    match(input, Token.DOWN, null); 
                    match(input,SCRIPT,FOLLOW_SCRIPT_in_condBase399); 

                    STRING12=(LocStatAST)match(input,STRING,FOLLOW_STRING_in_condBase401); 

                    match(input, Token.UP, null); 


                    String[] filterArgs = getFilterBody(STRING12);

                    // TEMPLATE REWRITE
                    // 79:4: -> condBase(body=%script(typeName={filterArgs[1]}, body={filterArgs[0]}))
                    {
                        retval.st = templateLib.getInstanceOf("condBase",new STAttrMap().put("body", templateLib.getInstanceOf("script",new STAttrMap().put("typeName", filterArgs[1]).put("body", filterArgs[0]))));
                    }



                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "condBase"


    public static class numOp_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };


    // $ANTLR start "numOp"
    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:82:1: numOp : ( EXACTLY_ONE | ONE_OR_MORE );
    public final LocStatGen.numOp_return numOp() throws RecognitionException {
        LocStatGen.numOp_return retval = new LocStatGen.numOp_return();
        retval.start = input.LT(1);


        try {
            // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:83:2: ( EXACTLY_ONE | ONE_OR_MORE )
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==EXACTLY_ONE) ) {
                alt9=1;
            }
            else if ( (LA9_0==ONE_OR_MORE) ) {
                alt9=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 9, 0, input);

                throw nvae;

            }
            switch (alt9) {
                case 1 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:83:4: EXACTLY_ONE
                    {
                    match(input,EXACTLY_ONE,FOLLOW_EXACTLY_ONE_in_numOp429); 

                    retval.st =new StringTemplate(templateLib,"n == 1");

                    }
                    break;
                case 2 :
                    // C:\\Users\\Charles\\Documents\\ANTLR\\lant\\LocStatGen.g:84:4: ONE_OR_MORE
                    {
                    match(input,ONE_OR_MORE,FOLLOW_ONE_OR_MORE_in_numOp436); 

                    retval.st =new StringTemplate(templateLib,"n > 0");

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "numOp"

    // Delegated rules


 

    public static final BitSet FOLLOW_defn_in_start51 = new BitSet(new long[]{0x0000000000000102L});
    public static final BitSet FOLLOW_DEFINE_in_defn73 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_STRING_in_defn75 = new BitSet(new long[]{0x000000000000C880L});
    public static final BitSet FOLLOW_func_in_defn77 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_COUNT_in_func108 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_count_in_func110 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_FRACTION_in_func126 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_count_in_func130 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_count_in_func134 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MEAN_in_func155 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_SUBJECT_in_func158 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_func160 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_condBase_in_func165 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_SCOPE_OP_in_func171 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_count_in_func173 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MEDIAN_in_func209 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_SUBJECT_in_func212 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_func214 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_condBase_in_func219 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_SCOPE_OP_in_func225 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_count_in_func227 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_SUBJECT_in_count266 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_count268 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_condBase_in_count273 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_COND_in_condBase312 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_COND_DEFAULT_in_condBase315 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_NOT_in_condBase319 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_SUBJECT_in_condBase325 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_condBase327 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_COND_in_condBase344 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_numOp_in_condBase346 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_SUBJECT_in_condBase349 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_condBase351 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_condBase_in_condBase356 = new BitSet(new long[]{0x0000000000000018L});
    public static final BitSet FOLLOW_COND_in_condBase375 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_NOT_in_condBase377 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_condBase_in_condBase381 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_COND_in_condBase397 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_SCRIPT_in_condBase399 = new BitSet(new long[]{0x0000000000200000L});
    public static final BitSet FOLLOW_STRING_in_condBase401 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_EXACTLY_ONE_in_numOp429 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ONE_OR_MORE_in_numOp436 = new BitSet(new long[]{0x0000000000000002L});

}